package com.ruoyi.server.api.coach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.errorCode.CommonException;
import com.ruoyi.server.api.coach.domain.CoachManagement;
import com.ruoyi.server.api.coach.service.ICoachManagementService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教练信息Controller
 * 
 * @author ZLP
 * @date 2024-06-12
 */
@RestController
@RequestMapping("/coach/coachmanagement")
public class CoachManagementController extends BaseController
{
    @Autowired
    private ICoachManagementService coachManagementService;

    /**
     * 查询教练信息列表
     */
    @PreAuthorize("@ss.hasPermi('coach:coachmanagement:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoachManagement coachManagement)
    {
        startPage();
        List<CoachManagement> list = coachManagementService.selectCoachManagementList(coachManagement);
        return getDataTable(list);
    }

    /**
     * 导出教练信息列表
     */
    @PreAuthorize("@ss.hasPermi('coach:coachmanagement:export')")
    @Log(title = "教练信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoachManagement coachManagement)
    {
        List<CoachManagement> list = coachManagementService.selectCoachManagementList(coachManagement);
        ExcelUtil<CoachManagement> util = new ExcelUtil<CoachManagement>(CoachManagement.class);
        util.exportExcel(response, list, "教练信息数据");
    }

    /**
     * 获取教练信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('coach:coachmanagement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(coachManagementService.selectCoachManagementById(id));
    }

    /**
     * 新增教练信息
     */
    @PreAuthorize("@ss.hasPermi('coach:coachmanagement:add')")
    @Log(title = "教练信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoachManagement coachManagement) throws CommonException {
        return toAjax(coachManagementService.insertCoachManagement(coachManagement));
    }

    /**
     * 修改教练信息
     */
    @PreAuthorize("@ss.hasPermi('coach:coachmanagement:edit')")
    @Log(title = "教练信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoachManagement coachManagement)
    {
        return toAjax(coachManagementService.updateCoachManagement(coachManagement));
    }

    /**
     * 删除教练信息
     */
    @PreAuthorize("@ss.hasPermi('coach:coachmanagement:remove')")
    @Log(title = "教练信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(coachManagementService.deleteCoachManagementByIds(ids));
    }
}
